package com.gitee.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.mapper.CookbookFoodMapper;
import com.gitee.pojo.CookbookFood;
import com.gitee.service.ICookbookFoodService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CookbookFoodServiceImpl extends ServiceImpl<CookbookFoodMapper, CookbookFood> implements ICookbookFoodService {

    /**
     * 更新库存
     *
     * @param cookbookId
     * @param foodId
     * @return
     */
    @Transactional
    @Override
    public Boolean updateByCookbookIdAndFoodId(Integer cookbookId, Integer foodId, Integer stock) {
        LambdaUpdateWrapper<CookbookFood> updateWrapper = new UpdateWrapper<CookbookFood>().lambda()
                .set(CookbookFood::getStock, stock)
                .eq(CookbookFood::getCookbookId, cookbookId)
                .eq(CookbookFood::getFoodId, foodId);
        return super.update(updateWrapper);
    }
}
